﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AusProject.OrderDataControls;
using AusProject.OrderComponents;
using System.IO;


namespace AusProject
{
    public partial class FormSupplierOrderDesigner : Form
    {
        private string backgroundImagePath = "";

        public FormSupplierOrderDesigner()
        {
            InitializeComponent();
            openFileDialogBackground.Filter = "Image files (*.bmp;*.jpg;*.gif;*.png)|*.bmp;*.jpg;*.gif;*.png|All files (*.*)|*.*";
            openFileDialogBackground.FileName = "";
            
            selectedControl = null;
            ShowProperties();
        }


        #region OrderForm DragDrop Ability

        DataBox newCreatedControl = null;

        private void panelOrderForm_DragEnter(object sender, DragEventArgs e)
        {
            newCreatedControl = (TextDataBox)e.Data.GetData(typeof(TextDataBox));
            if (newCreatedControl == null)
            {
                newCreatedControl = (NumberDataBox)e.Data.GetData(typeof(NumberDataBox));
            }
            if (newCreatedControl == null)
            {
                newCreatedControl = (DateDataBox)e.Data.GetData(typeof(DateDataBox));
            }
            if (newCreatedControl == null)
            {
                newCreatedControl = (DropListDataBox)e.Data.GetData(typeof(DropListDataBox));
            }
            if (newCreatedControl == null)
            {
                newCreatedControl = (CheckDataBox)e.Data.GetData(typeof(CheckDataBox));
            }
            if (newCreatedControl == null)
            {
                newCreatedControl = (TickDataBox)e.Data.GetData(typeof(TickDataBox));
            }
            if (newCreatedControl == null)
            {
                newCreatedControl = (TableDataBox)e.Data.GetData(typeof(TableDataBox));
            }

            if (newCreatedControl != null)
            {
                e.Effect = DragDropEffects.Copy;
                panelOrderForm.Controls.Add(newCreatedControl);
                newCreatedControl.Location = panelOrderForm.PointToClient(new Point(e.X, e.Y));
            }
            else
            {
                e.Effect = DragDropEffects.None;
            }
        }

        private void panelOrderForm_DragOver(object sender, DragEventArgs e)
        {
            if (newCreatedControl != null)
            {
                newCreatedControl.Location = panelOrderForm.PointToClient(new Point(e.X, e.Y));
            }
        }

        private void panelOrderForm_DragLeave(object sender, EventArgs e)
        {
            if (newCreatedControl != null)
            {
                panelOrderForm.Controls.Remove(newCreatedControl);
                newCreatedControl.Location = new Point(0, 0);
                newCreatedControl = null;
            }
        }

        private void panelOrderForm_DragDrop(object sender, DragEventArgs e)
        {
            InitNewControl(newCreatedControl);
        }

        #endregion


        #region Add New Control

        private void AddNewControl(DataBox databox)
        {
            panelOrderForm.Controls.Add(databox);
            InitNewControl(databox);
        }

        private void InitNewControl(DataBox databox)
        {
            databox.Enter += new System.EventHandler(this.control_Enter);
            databox.Move += new System.EventHandler(this.control_Move);
            databox.Resize += new System.EventHandler(this.control_Resize);
            databox.TitleChanged += new System.EventHandler(this.control_TitleChanged);

            if (databox is TableDataBox)
            {
                TableDataBox tableBox = (TableDataBox)databox;
                tableBox.SubBoxEnter += new System.EventHandler(this.control_Enter);
                tableBox.SubBoxMove += new System.EventHandler(this.control_Move);
                tableBox.SubBoxResize += new System.EventHandler(this.control_Resize);
                tableBox.SubBoxTitleChanged += new System.EventHandler(this.control_TitleChanged);
                tableBox.StartDragDrop();
            }

            databox.Focus();
        }


        private void btnTextDataBox_Click(object sender, EventArgs e)
        {
            AddNewControl(new TextDataBox());
        }

        private void btnTextDataBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                btnTextDataBox.DoDragDrop(new TextDataBox(), DragDropEffects.Copy);
            }
        }
        

        private void btnNumberDataBox_Click(object sender, EventArgs e)
        {
            AddNewControl(new NumberDataBox());
        }

        private void btnNumberDataBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                btnNumberDataBox.DoDragDrop(new NumberDataBox(), DragDropEffects.Copy);
            }
        }


        private void btnDateDataBox_Click(object sender, EventArgs e)
        {
            AddNewControl(new DateDataBox());
        }

        private void btnDateDataBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                btnDateDataBox.DoDragDrop(new DateDataBox(), DragDropEffects.Copy);
            }
        }


        private void btnDropListDataBox_Click(object sender, EventArgs e)
        {
            AddNewControl(new DropListDataBox());
        }

        private void btnDropListDataBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                btnDropListDataBox.DoDragDrop(new DropListDataBox(), DragDropEffects.Copy);
            }
        }


        private void btnCheckDataBox_Click(object sender, EventArgs e)
        {
            AddNewControl(new CheckDataBox());
        }

        private void btnCheckDataBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                btnCheckDataBox.DoDragDrop(new CheckDataBox(), DragDropEffects.Copy);
            }
        }


        private void btnTickDataBox_Click(object sender, EventArgs e)
        {
            AddNewControl(new TickDataBox());
        }

        private void btnTickDataBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                btnTickDataBox.DoDragDrop(new TickDataBox(), DragDropEffects.Copy);
            }
        }


        private void btnTableDataBox_Click(object sender, EventArgs e)
        {
            AddNewControl(new TableDataBox());
        }

        private void btnTableDataBox_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                btnTableDataBox.DoDragDrop(new TableDataBox(), DragDropEffects.Copy);
            }
        }

        #endregion


        private void btnBackground_Click(object sender, EventArgs e)
        {
            if (openFileDialogBackground.ShowDialog()!=System.Windows.Forms.DialogResult.Cancel)
            {
                try
                {
                    panelOrderForm.BackgroundImage = Image.FromFile(openFileDialogBackground.FileName);
                    backgroundImagePath = openFileDialogBackground.FileName;
                    txtFormBackground.Text = backgroundImagePath;
                }
                catch
                {
                    MessageBox.Show("Cannot load selected image file!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }


        DataBox selectedControl = null;

        private void ShowProperties()
        {
            if (selectedControl != null)
            {
                #region Show properties of selected control

                lblControlType.Text = selectedControl.ToString();

                if (!(selectedControl is TableDataBox))
                {
                    txtTitle.Text = selectedControl.Title;
                    txtTitle.Enabled = true;

                    txtDefaultValue.Text = selectedControl.DefaultValue;
                    txtDefaultValue.Enabled = true;

                    if (selectedControl.Editable)
                    {
                        cmbEditable.SelectedIndex = 0;
                    }
                    else
                    {
                        cmbEditable.SelectedIndex = 1;
                    }
                    cmbEditable.Enabled = true;

                    switch (selectedControl.BorderMode)
                    {
                        case DataControlBorderMode.None:
                            cmbBorderMode.SelectedIndex = 0;
                            break;
                        case DataControlBorderMode.Full:
                            cmbBorderMode.SelectedIndex = 1;
                            break;
                        case DataControlBorderMode.TitleOnly:
                            cmbBorderMode.SelectedIndex = 2;
                            break;
                        case DataControlBorderMode.ValueOnly:
                            cmbBorderMode.SelectedIndex = 3;
                            break;
                    }
                    cmbBorderMode.Enabled = true;

                    txtFont.Enabled = true;
                    txtFont.Text = selectedControl.Font.Name + "; " + selectedControl.Font.Size 
                        + (selectedControl.Font.Bold ? "; Bold" : "") + (selectedControl.Font.Italic ? "; Italic" : "");
                    btnSelectFont.Enabled = true;

                    if (selectedControl.Parent.Equals(panelOrderForm))
                    {
                        Select_cmbSummaryField_Item(selectedControl.SummaryFieldId);
                        cmbSummaryField.Enabled = true;
                    }
                }
                else
                {
                    txtTitle.Enabled = false;
                    txtDefaultValue.Enabled = false;
                    cmbEditable.Enabled = false;
                    cmbBorderMode.Enabled = false;
                    cmbSummaryField.SelectedIndex = -1;
                    cmbSummaryField.Enabled = false;
                }

                txtLeft.Text = selectedControl.Left.ToString();
                txtLeft.Enabled = true;
                txtTop.Text = selectedControl.Top.ToString();
                txtTop.Enabled = true;
                txtWidth.Text = selectedControl.Width.ToString();
                txtWidth.Enabled = true;
                txtHeight.Text = selectedControl.Height.ToString();
                txtHeight.Enabled = true;

                #endregion

                btnEditValueList.Enabled = (selectedControl is DropListDataBox) || (selectedControl is TickDataBox);

                btnDeleteControl.Enabled = true;
            }
            else
            {
                #region Clear and disable property controls

                lblControlType.Text = "None";

                txtTitle.Text = "";
                txtTitle.Enabled = false;

                txtDefaultValue.Text = "";
                txtDefaultValue.Enabled = false;

                cmbEditable.SelectedIndex = 0;
                cmbEditable.Enabled = false;

                cmbBorderMode.SelectedIndex = 0;
                cmbBorderMode.Enabled = false;

                txtFont.Text = "";
                txtFont.Enabled = false;
                btnSelectFont.Enabled = false;

                txtLeft.Text = "";
                txtLeft.Enabled = false;
                txtTop.Text = "";
                txtTop.Enabled = false;
                txtWidth.Text = "";
                txtWidth.Enabled = false;
                txtHeight.Text = "";
                txtHeight.Enabled = false;

                cmbSummaryField.SelectedIndex = -1;
                cmbSummaryField.Enabled = false;

                #endregion

                btnEditValueList.Enabled = false;

                btnDeleteControl.Enabled = false;
            }
        }

        
        #region Data control event Handlers

        private void control_Enter(object sender, EventArgs e)
        {
            selectedControl = (DataBox)sender;
            ShowProperties();
        }

        private void control_Resize(object sender, EventArgs e)
        {
            selectedControl = (DataBox)sender;

            //TODO: use form width/height instead of panelOrderForm.Width/Height

            if (selectedControl.Left + selectedControl.Width < 3)
            {
                selectedControl.Left = 3 - selectedControl.Width;
            }
            if (selectedControl.Left > panelOrderForm.Width - 3)
            {
                selectedControl.Left = panelOrderForm.Width - 3;
            }
            if (selectedControl.Top + selectedControl.Height < 3)
            {
                selectedControl.Top = 3 - selectedControl.Height;
            }
            if (selectedControl.Top > panelOrderForm.Height - 3)
            {
                selectedControl.Top = panelOrderForm.Height - 3;
            }
            ShowProperties();
        }

        private void control_Move(object sender, EventArgs e)
        {
            selectedControl = (DataBox)sender;
            if (selectedControl.Left + selectedControl.Width < 3)
            {
                selectedControl.Left = 3 - selectedControl.Width;
            }
            if (selectedControl.Left > panelOrderForm.Width - 3)
            {
                selectedControl.Left = panelOrderForm.Width - 3;
            }
            if (selectedControl.Top + selectedControl.Height < 3)
            {
                selectedControl.Top = 3 - selectedControl.Height;
            }
            if (selectedControl.Top > panelOrderForm.Height - 3)
            {
                selectedControl.Top = panelOrderForm.Height - 3;
            }
            ShowProperties();
        }

        private void control_TitleChanged(object sender, EventArgs e)
        {
            selectedControl = (DataBox)sender;
            ShowProperties();
        }

        #endregion Data control event Handlers


        private void txtTitle_Leave(object sender, EventArgs e)
        {
            if (selectedControl != null)
            {
                selectedControl.Title = txtTitle.Text;
                txtTitle.Text = selectedControl.Title;
            }
        }

        private void cmbEditable_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (selectedControl != null)
            {
                selectedControl.Editable = (cmbEditable.SelectedIndex == 0);
            }
        }

        private void cmbBorderMode_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (selectedControl != null)
            {
                switch (cmbBorderMode.SelectedIndex)
                {
                    case 0:
                        selectedControl.BorderMode = DataControlBorderMode.None;
                        break;
                    case 1:
                        selectedControl.BorderMode = DataControlBorderMode.Full;
                        break;
                    case 2:
                        selectedControl.BorderMode = DataControlBorderMode.TitleOnly;
                        break;
                    case 3:
                        selectedControl.BorderMode = DataControlBorderMode.ValueOnly;
                        break;
                }
            }
        }

        private void txtDefaultValue_Leave(object sender, EventArgs e)
        {
            if (selectedControl != null)
            {
                selectedControl.DefaultValue = txtDefaultValue.Text;
                txtDefaultValue.Text = selectedControl.DefaultValue;
            }
        }

        private void txtLeft_Leave(object sender, EventArgs e)
        {
            if (selectedControl != null)
            {
                int v;
                if (int.TryParse(txtLeft.Text, out v))
                {
                    if ((v + selectedControl.Width > 3) && (v < splitWhole.Panel1.Width - 3))
                    {
                        selectedControl.Left = v;
                    }
                }
                txtLeft.Text = selectedControl.Left.ToString();
            }
        }

        private void txtTop_Leave(object sender, EventArgs e)
        {
            if (selectedControl != null)
            {
                int v;
                if (int.TryParse(txtTop.Text, out v))
                {
                    if ((v + selectedControl.Height > 3) && (v < splitWhole.Panel1.Height - 3))
                    {
                        selectedControl.Top = v;
                    }
                }
                txtTop.Text = selectedControl.Top.ToString();
            }
        }

        private void txtWidth_Leave(object sender, EventArgs e)
        {
            if (selectedControl != null)
            {
                int v;
                if (int.TryParse(txtWidth.Text, out v))
                {
                    selectedControl.Width = v;
                }
                txtWidth.Text = selectedControl.Width.ToString();
            }
        }

        private void txtHeight_Leave(object sender, EventArgs e)
        {
            if (selectedControl != null)
            {
                int v;
                if (int.TryParse(txtHeight.Text, out v))
                {
                    selectedControl.Height = v;
                }
                txtHeight.Text = selectedControl.Height.ToString();
            }
        }

        private void txtFormWidth_Leave(object sender, EventArgs e)
        {
            int v;
            if (int.TryParse(txtFormWidth.Text, out v))
            {
                panelOrderForm.Width = v;
            }
            txtFormWidth.Text = panelOrderForm.Width.ToString();
        }

        private void txtFormHeight_Leave(object sender, EventArgs e)
        {
            int v;
            if (int.TryParse(txtFormHeight.Text, out v))
            {
                panelOrderForm.Height = v;
            }
            txtFormHeight.Text = panelOrderForm.Height.ToString();
        }

        private void txtTitle_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtTitle_Leave(null, null);
            }
        }

        private void txtLeft_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtLeft_Leave(null, null);
            }
        }

        private void txtTop_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtTop_Leave(null, null);
            }
        }

        private void txtWidth_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtWidth_Leave(null, null);
            }
        }

        private void txtHeight_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtHeight_Leave(null, null);
            }
        }

        private void txtFormWidth_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtFormWidth_Leave(null, null);
            }
        }

        private void txtFormHeight_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                txtFormHeight_Leave(null, null);
            }
        }

        private void btnDeleteControl_Click(object sender, EventArgs e)
        {
            if (selectedControl != null)
            {
                // selectedControl may be a subBox inside a TableBox
                selectedControl.Parent.Controls.Remove(selectedControl);

                selectedControl = null;
                ShowProperties();
            }
        }

        private void panelOrderForm_MouseClick(object sender, MouseEventArgs e)
        {
            panelOrderForm.Focus();
            selectedControl = null;
            ShowProperties();
        }

        private void txtTitle_Enter(object sender, EventArgs e)
        {
            txtTitle.SelectAll();
        }

        private void txtDefaultValue_Enter(object sender, EventArgs e)
        {
            txtDefaultValue.SelectAll();
        }

        private void txtLeft_Enter(object sender, EventArgs e)
        {
            txtLeft.SelectAll();
        }

        private void txtTop_Enter(object sender, EventArgs e)
        {
            txtTop.SelectAll();
        }

        private void txtWidth_Enter(object sender, EventArgs e)
        {
            txtWidth.SelectAll();
        }

        private void txtHeight_Enter(object sender, EventArgs e)
        {
            txtHeight.SelectAll();
        }

        private void txtFormWidth_Enter(object sender, EventArgs e)
        {
            txtFormWidth.SelectAll();
        }

        private void txtFormHeight_Enter(object sender, EventArgs e)
        {
            txtFormHeight.SelectAll();
        }

        private void cmbEditable_MouseClick(object sender, MouseEventArgs e)
        {
            cmbEditable.DroppedDown = true;
        }

        private void cmbBorderMode_MouseClick(object sender, MouseEventArgs e)
        {
            cmbBorderMode.DroppedDown = true;
        }


        private void btnEditValueList_Click(object sender, EventArgs e)
        {
            if (selectedControl is DropListDataBox)
            {
                FormDropListValues frmValueListEditor = new FormDropListValues();
                frmValueListEditor.ListValue = ((DropListDataBox)selectedControl).ListValue;
                frmValueListEditor.ShowDialog();
                if (frmValueListEditor.HasAccepted)
                {
                    ((DropListDataBox)selectedControl).ListValue = frmValueListEditor.ListValue;
                }
            }
            else  // must be TickBoxControl
            {
                FormTickBoxOptions frmTickBoxOptions = new FormTickBoxOptions();
                frmTickBoxOptions.Option1Label = ((TickDataBox)selectedControl).Option1Label;
                frmTickBoxOptions.Option2Label = ((TickDataBox)selectedControl).Option2Label;
                frmTickBoxOptions.ShowDialog();
                if (frmTickBoxOptions.HasAccepted)
                {
                    ((TickDataBox)selectedControl).Option1Label = frmTickBoxOptions.Option1Label;
                    ((TickDataBox)selectedControl).Option2Label = frmTickBoxOptions.Option2Label;
                }
            }
        }

        private void txtFormTitle_Enter(object sender, EventArgs e)
        {
            txtFormTitle.SelectAll();
        }

        private void txtFormBackground_Enter(object sender, EventArgs e)
        {
            txtFormBackground.SelectAll();
        }


        private bool accepted = false;

        public bool Accepted
        {
            get { return accepted; }
        }


        private void btnSave_Click(object sender, EventArgs e)
        {
            accepted = true;
            this.Close();
        }

        private void btnDiscard_Click(object sender, EventArgs e)
        {
            accepted = false;
            this.Close();
        }

        
        private void btnTestOrderForm_Click(object sender, EventArgs e)
        {
            FormSupplierOrderRuntime runForm = new FormSupplierOrderRuntime();
            runForm.LoadForm(ExportFormInfo(), false);
            this.Hide();
            runForm.ShowDialog();
            this.Show();
        }


        public bool ImportFormInfo(SupplierOrderFormInfo formInfo)
        {
            try
            {
                txtFormTitle.Text = formInfo.Title;
                
                txtFormWidth.Text = formInfo.Width.ToString();
                panelOrderForm.Width = formInfo.Width;

                txtFormHeight.Text = formInfo.Height.ToString();
                panelOrderForm.Height = formInfo.Height;

                txtFormBackground.Text = formInfo.BackgroundImagePath;
                backgroundImagePath = formInfo.BackgroundImagePath;

                try
                {
                    panelOrderForm.BackgroundImage = Image.FromFile(backgroundImagePath);
                }
                catch
                {
                    MessageBox.Show("Cannot load the form background!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtFormBackground.Text = "";
                    backgroundImagePath = "";
                }

                panelOrderForm.Controls.Clear();
                foreach (DataBoxInfo dataBoxInfo in formInfo.ListOfDataBox)
                {
                    AddNewControl(dataBoxInfo.CreateDataBox());
                }

                this.Invalidate();
                return true;
            }
            catch
            {
                return false;
            }
        }
        
        public SupplierOrderFormInfo ExportFormInfo()
        {
            List<DataBoxInfo> listOfDataBox = new List<DataBoxInfo>();
            foreach (DataBox databox in panelOrderForm.Controls)
            {
                listOfDataBox.Add(databox.ExportDataBoxInfo());
            }

            return new SupplierOrderFormInfo(txtFormTitle.Text, panelOrderForm.Width, panelOrderForm.Height, backgroundImagePath, listOfDataBox);
        }


        public void SetOrderComponentType(OrderComponentInfo ocInfo)
        {
            cmbSummaryField.Items.Clear();

            cmbSummaryField.Items.Add(new ComponentColumnInfo(-1, "<unbound>", false, 0));

            foreach (ComponentColumnInfo col in ocInfo.Columns)
            {
                if (!string.IsNullOrEmpty(col.Title))
                {
                    cmbSummaryField.Items.Add(col);
                }
            }
        }


        public void Select_cmbSummaryField_Item(int id)
        {
            cmbSummaryField.SelectedIndex = -1;
            for (int i = 0; i < cmbSummaryField.Items.Count; i++)
            {
                if (((ComponentColumnInfo)cmbSummaryField.Items[i]).Id == id)
                {
                    cmbSummaryField.SelectedIndex = i;
                    break;
                }
            }
        }

        private void cmbSummaryField_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbSummaryField.SelectedItem != null)
            {
                int sumFieldId = ((ComponentColumnInfo)cmbSummaryField.SelectedItem).Id;

                if (sumFieldId >= 0)
                {
                    bool flag = true;

                    foreach (DataBox dbox in this.panelOrderForm.Controls)
                    {
                        if (dbox.SummaryFieldId == sumFieldId)
                        {
                            if (!dbox.Equals(selectedControl))
                            {
                                if (MessageBox.Show("This summary field has been bound to another databox.\nDo you want to rebound?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                                {
                                    dbox.SummaryFieldId = -1;
                                }
                                else
                                {
                                    flag = false;   // user cancel
                                    Select_cmbSummaryField_Item(selectedControl.SummaryFieldId);
                                }
                                break;
                            }
                            else
                            {
                                flag = false;   // already bound
                            }
                        }
                    }

                    if (flag)
                    {
                        selectedControl.SummaryFieldId = sumFieldId;
                    }
                }
                else
                {
                    selectedControl.SummaryFieldId = -1;    // unbound
                }
            }
        }

        private void btnSelectFont_Click(object sender, EventArgs e)
        {
            fontDialogDataBox.Font = selectedControl.Font;
            try
            {
                if (fontDialogDataBox.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    selectedControl.Font = fontDialogDataBox.Font;
                }
            }
            catch
            {
                MessageBox.Show("The font you have selected is invalid!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ShowProperties();
            }
        }


        public void SetTitle(string formTitle, int formID)
        {
            string oFormTitle = string.IsNullOrEmpty(formTitle) ? "" : " - " + formTitle;
            string oFormID = formID >= 0 ? " (#" + formID + ")" : " (NoID)";
            this.Text = "Supplier Order Form Designer" + oFormTitle + oFormID;
        }
    }
}
